<template>
  <div class="home-page">
    <el-container>
      <!-- 侧边栏 -->
      <el-aside width="200">
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          :router="true"
          :collapse="isCollapse"
        >
          <qf-sub-menu :sideMenu="menuList"></qf-sub-menu>
        </el-menu>
      </el-aside>
      <el-container>
        <!-- 顶部栏 -->
        <el-header
          ><el-row type="flex" class="row-bg" justify="space-between">
            <el-col :span="6"
              ><div class="grid-content">
                <i
                  class="iconfont icon-shouqi"
                  @click="isCollapse = !isCollapse"
                ></i></div
            ></el-col>
            <el-col :span="6"
              ><div class="grid-content">杀猪管理系统</div></el-col
            >
            <el-col :span="6"
              ><div class="grid-content">
                <el-avatar
                  :size="40"
                  fit="fit"
                  src="http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIzXDib7zrmdYxdEQpYk85B26DZAJS6PUJC7ic4Fydibdz9L2gU3hloPcibuyo0xAFztxqPbgdVWp1zpQ/132"
                ></el-avatar>
                <span>欢迎您:</span>
                <b class="nickname">{{ userInfo.nickname }}</b>
                <span class="quit" @click="quit">退出 </span>
              </div></el-col
            >
          </el-row></el-header
        >
        <!-- 主题内容 -->
        <el-main>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item 
            :to="{ path:crumb.path}" 
            v-for="(crumb,index) in crumbs"
            :key="index">
              {{crumb.meta.name}}
            </el-breadcrumb-item>
          </el-breadcrumb>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script> 
// import { getLoginLog } from "@/api";
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState(["userInfo", "menuList","crumbs"]),

  },
  mounted() {
    // getLoginLog().then((res) => {
    //   console.log(res);
    // });
  },
  data() {
    return {
      isCollapse: false,
    };
  },
  methods: {
    quit() {
      // 1.退出登陆
      // 2.清除token和userinfo
      // 3.跳转到登录页
      localStorage.removeItem("crlm-token");
      localStorage.removeItem("crlm-userinfo");

      this.$router.push("/login");
      //刷新页面
      window.location.reload();
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
};
</script>

<style scoped>
/* 顶部栏样式 */
.grid-content {
  border-radius: 4px;
  min-height: 60px;
  color: #fff;
}
.row-bg {
  background: linear-gradient(90deg, #235699, #b11c1c);
}
/* 修改顶部栏头像的样式 */
.el-avatar.el-avatar--circle {
  vertical-align: middle;
  margin-right: 10px;
}
/*顶部栏退出样式 */
.quit {
  margin-left: 10px;
}
.nickname {
  margin-left: 10px;
}
/*顶部栏背景样式 */
.el-header {
  color: #333;
  text-align: center;
  line-height: 60px;
  padding: 0;
}

/* 侧边栏样式 */
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.icon-shouqi {
  font-size: 30px;
  position: absolute;
  left: 30px;
}

/* 整体布局样式 */
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>

